#!/usr/bin/env ruby

p "Use age: log.rb dd|svn|mysql" unless ARGV.size!=1 || !(%w{dd svn mysql}.include? ARGV[0].downcase)

$LOGPATH=File.dirname(__FILE__)

# $0是整个ruby执行文件最顶层文件的路径。因此使用if __FILE__==$0可以判断当前ruby文件是被引用还是被执行。
p "Can't exec #{__FILE__} in another command." unless __FILE__==$0

if %w{dd svn mysql}.include? ARGV[0].downcase then
  if system(%Q{tar -zcvf #{ARGV[0].downcase}-performance.tar.gz monitor/ #{ARGV[0].downcase}.log stdout.log nbd-server.log}) then
    p "Create Success."
    `ls -lh #{ARGV[0].downcase}-performance.tar.gz`
  else
    p "Create Fail."
  end
end